﻿namespace Dcms.Common
{
    using System;
    using System.IO;
    using System.Xml.Serialization;

    public class DcmsConfig
    {
        public static object Load(Type type, string filename)
        {
            FileStream fs = null;
            object csTemp0000;
            try
            {
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                csTemp0000 = new XmlSerializer(type).Deserialize(fs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (fs != null) fs.Close();
            }
            return csTemp0000;
        }

        public static void Save(object obj, string filename)
        {
            FileStream fs = null;
            try
            {
                fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                new XmlSerializer(obj.GetType()).Serialize((Stream) fs, obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (fs != null) fs.Close();
            }
        }
    }
}

